<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title></title>
		<link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<script src="../js/jquery-3.5.1.js"></script>
		<script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="login.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			html,
			body,
			.container {
				height: 100%;
				width: 100%;
			}
			#one{
				position: relative;
				top: 50%;
				left: 50%;
				transform: translate(-50%,-50%);
				 width: 550px;
				/*
				height: 100px;
				background-color: #000000; */
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div id="one">
				<form class="form-horizontal">
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">名称:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="pit_name" placeholder="楼的编号">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputPassword3" class="col-sm-2 control-label">简介:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="inp_jjie" placeholder="楼的介绍">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="inputEmail3" class="col-sm-2 control-label">管理员姓名:</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" id="ipt_xm" placeholder="姓名">
				    </div>
				  </div>
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button id="btn_save" type="button" class="btn btn-default btn-primary" onclick="save()">保存</button>
					   <button type="button" class="btn btn-default btn-primary">返回</button>
				    </div>
				  </div>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			let floorarr=localStorage.getItem("floorarr");
				let edit=JSON.parse(sessionStorage.getItem("editname_add_floor"));
				if (edit) {
					$("#pit_name").val(edit.name);
					$("#inp_jjie").val(edit.introduction);
					$("#ipt_xm").val(edit.Fullname);
				}
			function save(){
				floorarr=JSON.parse(floorarr);
				console.log(floorarr);
				let name=$("#pit_name").val();
				let introduction=$("#inp_jjie").val();
				let xm=$("#ipt_xm").val();
				let tem=0;
				for(let item of floorarr){
					let id1=parseInt(item.id);
					if (tem<id1) {
						tem=id1;
					}
				}
				
				let obj={
					id:tem+1,
					name:name,
					introduction :introduction ,
					Fullname:xm,
				}
				if (floorarr) {
					for (let item of floorarr) {
						if (name===item.name && item.Fullname) {
							alert("此楼以有管理员");
							return;
						}
					}
					floorarr.push(obj);
					localStorage.setItem("floorarr",JSON.stringify(floorarr));
					console.log(obj);
					location.href="yem_floor.html"
				} else{
					alert("输入完整信息");
				}
			}
			
		</script>
	</body>
</html>
